from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

# 获取Edge浏览器驱动
driver = webdriver.Edge()
# 打开指定网址
driver.get('https://www.jiuxian.com/')
# 强等2秒
sleep(1)
# 窗口最大化
driver.maximize_window()
sleep(1)
# 点击请登录
driver.find_element(By.CLASS_NAME,'headerLogin').click()
sleep(1)
# 输入账号
driver.find_element(By.ID,"userName").send_keys('18185603008')
sleep(2)
# 输入密码
driver.find_element(By.ID,'password').send_keys('123456Aa')
sleep(10)
#点击登录
driver.find_element(By.NAME,'bi_Usuallogin').click()
sleep(2)
# 点击确定
driver.find_element(By.ID,'bindSub').click()
sleep(2)
# 断言 jxw824726828
dy1 = driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span').text
assert dy1 == 'jxw824726828'
print(dy1)
sleep(2)
# 点击输入框下的五粮液
driver.find_element(By.LINK_TEXT,'五粮液').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 点击选择的酒
driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[6]/ul/li[5]/div[2]/div[1]/a/img').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 修改商品数量为2
driver.find_element(By.ID,'_nub').clear()
sleep(2)
# 输入数量2
driver.find_element(By.ID,'_nub').send_keys('2')
sleep(2)
# 点击加入购物车
driver.find_element(By.NAME,'detail_jiarugouwuche').click()
sleep(2)
# 断言2 已成功加入购物车
dy2 = driver.find_element(By.XPATH,'//*[@id="u-buy-layId"]/div/div[2]/span').text
print(dy2)
assert '已成功加入购物车' == dy2
sleep(2)
# 点击查看购物车
driver.find_element(By.XPATH,'//*[@id="rSidebarCart"]/div/span').click()
sleep(2)
# 点击继续购物
driver.find_element(By.CLASS_NAME,'detail_jixugouwu').click()
sleep(2)
# 点击去购物车结算
driver.find_element(By.CLASS_NAME,'rsCartBut-bay').click()
sleep(2)
# 点击去结算
driver.find_element(By.XPATH,'//*[@id="cart_container"]/div[3]/div[3]/a[1]').click()
sleep(2)
# 断言3 北京北京市昌平区南口镇南大街21号
dy3 = driver.find_element(By.XPATH,'//*[@id="addressListDiv"]/div[2]/ul/li/div[2]/div[1]').text
print(dy3)
sleep(2)
assert dy3 in '南大街21号'
sleep(2)
# 断言4 支付方式 货到付款
dy4 = driver.find_element(By.XPATH,'/html/body/div[3]/div/div[2]/div[2]/div[1]/span').text
print(dy4)
assert '货到付款' not in dy4
sleep(2)







